package com.lifeng.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lifeng.domain.SysUser;
import com.lifeng.mapper.SysUserMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author:lifeng
 * @date:2020/4/20 18:07
 */
@Service
public class SysUserService extends ServiceImpl<SysUserMapper, SysUser>{

    public IPage<SysUser> listPage(Integer pageNum,Integer pageSize,SysUser sysUser){
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(sysUser.getUserName()),"username",sysUser.getUserName());
        queryWrapper.like(!StringUtils.isEmpty(sysUser.getRealName()),"realname",sysUser.getRealName());
        queryWrapper.eq(sysUser.getAge()!=null,"age",sysUser.getAge());
        IPage<SysUser> page = page(new Page<>(pageNum.longValue(),pageSize.longValue()), queryWrapper);
        return page;
    }

    public SysUser findByUserNameAndPwd(String userName,String passWord){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("username",userName);
        queryWrapper.eq("passWord",passWord);
        return getOne(queryWrapper);
    }

    public void add(SysUser sysUser){
        save(sysUser);
    }

    public void update(SysUser sysUser){
        updateById(sysUser);
    }

    public void delete(List<Integer> ids){
        removeByIds(ids);
    }
}
